/*
 * RamosManualesView.java
 */
package ramosmanuales;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamResult;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import org.jdesktop.application.Action;
import ramosmanuales.data.vo.ReporteConciliacion;
import ramosmanuales.data.vo.ReporteContenido;
import ramosmanuales.util.Quincena;
import ramosmanuales.data.xml.RamoManual;
import ramosmanuales.data.xml.Derechohabiente;
import ramosmanuales.data.xml.OrdenDescuento;
import ramosmanuales.data.xml.Pago;

/**
 * 'Automatizacion de Ramos Manuales' application main frame
 * @author arlopez
 */
public class RamosManualesView extends FrameView implements ActionListener {

    private static URL url;//representa la ruta del recurso que contiene el archivo de pagos
    private static JAXBContext context;
    private static Unmarshaller unmarshaller;
    private static Marshaller marshaller;
    private static RamoManual rootNode;
    private static Derechohabiente currentElement;//representa el element actualmente en proceso de captura
    private int cursor;//representa el indice del element actual en la ordenList
    private Quincena currentStartRange;//rango initial de od's del element actual
    private Quincena currentEndRange;//rango final de od's del element actual
    private javax.swing.JFileChooser siicDataFileChooser;
    private static final int REPORTE_CONTENIDO = 0;
    private static final int REPORTE_CONCILIACION = 1;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JLabel amountLabel;
    private javax.swing.JTextField amountTextField;
    private javax.swing.JLabel brokenFNLabel;
    private javax.swing.JTextField brokenFNTextField;
    private javax.swing.JLabel curpLabel;
    private javax.swing.JTextField curpTextField;
    private javax.swing.JComboBox dealTypeComboBox;
    private javax.swing.JLabel dealTypeLabel;
    private javax.swing.JLabel delegacionLabel;
    private javax.swing.JTextField delegacionTextField;
    private javax.swing.JLabel endFNLabel;
    private javax.swing.JSpinner endFNSpinner;
    private javax.swing.JSpinner endYearSpinner;
    private javax.swing.JButton exitButton;
    private javax.swing.JTextField firstNameTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lastNameLabel;
    private javax.swing.JTextField lastNameTextField;
    private javax.swing.JButton loadXMLButton;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton nextElementButton;
    private javax.swing.JLabel noIsssteLabel;
    private javax.swing.JTextField noIsssteTextField;
    private javax.swing.JLabel pagaduriaLabel;
    private javax.swing.JTextField pagaduriaTextField;
    private javax.swing.JTable paymentTable;
    private javax.swing.JButton previousElementButton;
    private javax.swing.JLabel ramoLabel;
    private javax.swing.JTextField ramoTextField;
    private javax.swing.JTable regularizationTable;
    private javax.swing.JButton removeButton;
    private javax.swing.JButton reporteConciliacionButton;
    private javax.swing.JButton reporteContenidoButton;
    private javax.swing.JLabel rfcLabel;
    private javax.swing.JTextField rfcTextField;
    private javax.swing.JButton saveFileButton;
    private javax.swing.JButton searchButton;
    private javax.swing.JLabel secondNameLabel;
    private javax.swing.JTextField secondNameTextField;
    private javax.swing.JLabel startFNLabel;
    private javax.swing.JSpinner startFNSpinner;
    private javax.swing.JSpinner startYearSpinner;
    private javax.swing.JLabel totalFNLabel;
    private javax.swing.JTextField totalFNTextField;
    private javax.swing.JTextField totalFNsTextField;
    private javax.swing.JLabel totalLabel;
    private javax.swing.JTextField totalPayTextField;
    private javax.swing.JLabel totalPaymentLabel;
    private javax.swing.JTextField totalPaymentTextField;
    // End of variables declaration//GEN-END:variables
    private JDialog searchDialog;

    /**
     * Creates a new instance of the main frame
     * @param app
     * @throws JAXBException
     * @throws IOException
     */
    public RamosManualesView(SingleFrameApplication app) throws JAXBException, IOException {
        super(app);
        initComponents();
        componentEnabled(false);
        siicDataFileChooser = new javax.swing.JFileChooser();
        addButton.addActionListener(this);
        removeButton.addActionListener(this);
        searchButton.addActionListener(this);
        saveFileButton.addActionListener(this);
        loadXMLButton.addActionListener(this);
        nextElementButton.addActionListener(this);
        previousElementButton.addActionListener(this);
        reporteContenidoButton.addActionListener(this);
        reporteConciliacionButton.addActionListener(this);
        getInstanceJAXBContext();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        reporteContenidoButton = new javax.swing.JButton();
        saveFileButton = new javax.swing.JButton();
        previousElementButton = new javax.swing.JButton();
        nextElementButton = new javax.swing.JButton();
        searchButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        loadXMLButton = new javax.swing.JButton();
        reporteConciliacionButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        delegacionLabel = new javax.swing.JLabel();
        delegacionTextField = new javax.swing.JTextField();
        ramoLabel = new javax.swing.JLabel();
        ramoTextField = new javax.swing.JTextField();
        pagaduriaLabel = new javax.swing.JLabel();
        pagaduriaTextField = new javax.swing.JTextField();
        noIsssteLabel = new javax.swing.JLabel();
        noIsssteTextField = new javax.swing.JTextField();
        rfcLabel = new javax.swing.JLabel();
        rfcTextField = new javax.swing.JTextField();
        curpLabel = new javax.swing.JLabel();
        curpTextField = new javax.swing.JTextField();
        lastNameLabel = new javax.swing.JLabel();
        lastNameTextField = new javax.swing.JTextField();
        secondNameLabel = new javax.swing.JLabel();
        secondNameTextField = new javax.swing.JTextField();
        nameLabel = new javax.swing.JLabel();
        firstNameTextField = new javax.swing.JTextField();
        brokenFNTextField = new javax.swing.JTextField();
        dealTypeLabel = new javax.swing.JLabel();
        brokenFNLabel = new javax.swing.JLabel();
        dealTypeComboBox = new javax.swing.JComboBox();
        startFNLabel = new javax.swing.JLabel();
        endFNLabel = new javax.swing.JLabel();
        amountLabel = new javax.swing.JLabel();
        totalFNLabel = new javax.swing.JLabel();
        totalLabel = new javax.swing.JLabel();
        amountTextField = new javax.swing.JTextField();
        totalFNTextField = new javax.swing.JTextField();
        totalPayTextField = new javax.swing.JTextField();
        totalPaymentLabel = new javax.swing.JLabel();
        totalFNsTextField = new javax.swing.JTextField();
        totalPaymentTextField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        regularizationTable = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        paymentTable = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        addButton = new javax.swing.JButton();
        removeButton = new javax.swing.JButton();
        startYearSpinner = new javax.swing.JSpinner();
        startFNSpinner = new javax.swing.JSpinner();
        endYearSpinner = new javax.swing.JSpinner();
        endFNSpinner = new javax.swing.JSpinner();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ramosmanuales.RamosManualesApp.class).getContext().getResourceMap(RamosManualesView.class);
        mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
        mainPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(1024, 720));

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setName("jPanel2"); // NOI18N

        reporteContenidoButton.setBackground(resourceMap.getColor("reporteContenidoButton.background")); // NOI18N
        reporteContenidoButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        reporteContenidoButton.setForeground(resourceMap.getColor("reporteContenidoButton.foreground")); // NOI18N
        reporteContenidoButton.setText(resourceMap.getString("reporteContenidoButton.text")); // NOI18N
        reporteContenidoButton.setName("reporteContenidoButton"); // NOI18N

        saveFileButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        saveFileButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        saveFileButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        saveFileButton.setText(resourceMap.getString("saveFileButton.text")); // NOI18N
        saveFileButton.setName("saveFileButton"); // NOI18N

        previousElementButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        previousElementButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        previousElementButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        previousElementButton.setText(resourceMap.getString("previousElementButton.text")); // NOI18N
        previousElementButton.setName("previousElementButton"); // NOI18N

        nextElementButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        nextElementButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        nextElementButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        nextElementButton.setText(resourceMap.getString("nextElementButton.text")); // NOI18N
        nextElementButton.setName("nextElementButton"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(ramosmanuales.RamosManualesApp.class).getContext().getActionMap(RamosManualesView.class, this);
        searchButton.setAction(actionMap.get("showSearchDialog")); // NOI18N
        searchButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        searchButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        searchButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        searchButton.setText(resourceMap.getString("searchButton.text")); // NOI18N
        searchButton.setName("searchButton"); // NOI18N

        exitButton.setAction(actionMap.get("salir")); // NOI18N
        exitButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        exitButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        exitButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        exitButton.setText(resourceMap.getString("exitButton.text")); // NOI18N
        exitButton.setName("exitButton"); // NOI18N
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        loadXMLButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        loadXMLButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        loadXMLButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        loadXMLButton.setText(resourceMap.getString("loadXMLButton.text")); // NOI18N
        loadXMLButton.setName("loadXMLButton"); // NOI18N

        reporteConciliacionButton.setBackground(resourceMap.getColor("reporteConciliacionButton.background")); // NOI18N
        reporteConciliacionButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        reporteConciliacionButton.setText(resourceMap.getString("reporteConciliacionButton.text")); // NOI18N
        reporteConciliacionButton.setName("reporteConciliacionButton"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(reporteContenidoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(reporteConciliacionButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addComponent(loadXMLButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveFileButton)
                .addGap(40, 40, 40)
                .addComponent(searchButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(previousElementButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nextElementButton)
                .addGap(51, 51, 51)
                .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exitButton)
                    .addComponent(reporteContenidoButton)
                    .addComponent(reporteConciliacionButton)
                    .addComponent(previousElementButton)
                    .addComponent(nextElementButton)
                    .addComponent(searchButton)
                    .addComponent(loadXMLButton)
                    .addComponent(saveFileButton))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel1.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel1.setName("jPanel1"); // NOI18N

        delegacionLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        delegacionLabel.setText(resourceMap.getString("delegacionLabel.text")); // NOI18N
        delegacionLabel.setName("delegacionLabel"); // NOI18N

        delegacionTextField.setBackground(resourceMap.getColor("delegacionTextField.background")); // NOI18N
        delegacionTextField.setEditable(false);
        delegacionTextField.setText(resourceMap.getString("delegacionTextField.text")); // NOI18N
        delegacionTextField.setName("delegacionTextField"); // NOI18N

        ramoLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        ramoLabel.setText(resourceMap.getString("ramoLabel.text")); // NOI18N
        ramoLabel.setName("ramoLabel"); // NOI18N

        ramoTextField.setBackground(resourceMap.getColor("ramoTextField.background")); // NOI18N
        ramoTextField.setEditable(false);
        ramoTextField.setText(resourceMap.getString("ramoTextField.text")); // NOI18N
        ramoTextField.setName("ramoTextField"); // NOI18N

        pagaduriaLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        pagaduriaLabel.setText(resourceMap.getString("pagaduriaLabel.text")); // NOI18N
        pagaduriaLabel.setName("pagaduriaLabel"); // NOI18N

        pagaduriaTextField.setBackground(resourceMap.getColor("pagaduriaTextField.background")); // NOI18N
        pagaduriaTextField.setEditable(false);
        pagaduriaTextField.setText(resourceMap.getString("pagaduriaTextField.text")); // NOI18N
        pagaduriaTextField.setName("pagaduriaTextField"); // NOI18N

        noIsssteLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        noIsssteLabel.setText(resourceMap.getString("noIsssteLabel.text")); // NOI18N
        noIsssteLabel.setName("noIsssteLabel"); // NOI18N

        noIsssteTextField.setBackground(resourceMap.getColor("noIsssteTextField.background")); // NOI18N
        noIsssteTextField.setEditable(false);
        noIsssteTextField.setText(resourceMap.getString("noIsssteTextField.text")); // NOI18N
        noIsssteTextField.setName("noIsssteTextField"); // NOI18N

        rfcLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        rfcLabel.setText(resourceMap.getString("rfcLabel.text")); // NOI18N
        rfcLabel.setName("rfcLabel"); // NOI18N

        rfcTextField.setBackground(resourceMap.getColor("rfcTextField.background")); // NOI18N
        rfcTextField.setEditable(false);
        rfcTextField.setText(resourceMap.getString("rfcTextField.text")); // NOI18N
        rfcTextField.setName("rfcTextField"); // NOI18N

        curpLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        curpLabel.setText(resourceMap.getString("curpLabel.text")); // NOI18N
        curpLabel.setName("curpLabel"); // NOI18N

        curpTextField.setBackground(resourceMap.getColor("curpTextField.background")); // NOI18N
        curpTextField.setEditable(false);
        curpTextField.setText(resourceMap.getString("curpTextField.text")); // NOI18N
        curpTextField.setName("curpTextField"); // NOI18N

        lastNameLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        lastNameLabel.setText(resourceMap.getString("lastNameLabel.text")); // NOI18N
        lastNameLabel.setName("lastNameLabel"); // NOI18N

        lastNameTextField.setBackground(resourceMap.getColor("lastNameTextField.background")); // NOI18N
        lastNameTextField.setEditable(false);
        lastNameTextField.setText(resourceMap.getString("lastNameTextField.text")); // NOI18N
        lastNameTextField.setName("lastNameTextField"); // NOI18N

        secondNameLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        secondNameLabel.setText(resourceMap.getString("secondNameLabel.text")); // NOI18N
        secondNameLabel.setName("secondNameLabel"); // NOI18N

        secondNameTextField.setBackground(resourceMap.getColor("secondNameTextField.background")); // NOI18N
        secondNameTextField.setEditable(false);
        secondNameTextField.setText(resourceMap.getString("secondNameTextField.text")); // NOI18N
        secondNameTextField.setName("secondNameTextField"); // NOI18N

        nameLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        nameLabel.setText(resourceMap.getString("nameLabel.text")); // NOI18N
        nameLabel.setName("nameLabel"); // NOI18N

        firstNameTextField.setBackground(resourceMap.getColor("firstNameTextField.background")); // NOI18N
        firstNameTextField.setEditable(false);
        firstNameTextField.setText(resourceMap.getString("firstNameTextField.text")); // NOI18N
        firstNameTextField.setName("firstNameTextField"); // NOI18N

        brokenFNTextField.setBackground(resourceMap.getColor("brokenFNTextField.background")); // NOI18N
        brokenFNTextField.setEditable(false);
        brokenFNTextField.setText(resourceMap.getString("brokenFNTextField.text")); // NOI18N
        brokenFNTextField.setName("brokenFNTextField"); // NOI18N

        dealTypeLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        dealTypeLabel.setText(resourceMap.getString("dealTypeLabel.text")); // NOI18N
        dealTypeLabel.setName("dealTypeLabel"); // NOI18N

        brokenFNLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        brokenFNLabel.setText(resourceMap.getString("brokenFNLabel.text")); // NOI18N
        brokenFNLabel.setName("brokenFNLabel"); // NOI18N

        dealTypeComboBox.setFont(resourceMap.getFont("dealTypeComboBox.font")); // NOI18N
        dealTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NORMAL", "LICENCIA", "BAJA", "DEFUNCION", "PENSIONADO", "RETIRO VOLUNTARIO", "NO ES DEL RAMO", "POR APLICAR", "SIN INFORMACION" }));
        dealTypeComboBox.setName("dealTypeComboBox"); // NOI18N
        dealTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dealTypeComboBoxActionPerformed(evt);
            }
        });

        startFNLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        startFNLabel.setText(resourceMap.getString("startFNLabel.text")); // NOI18N
        startFNLabel.setName("startFNLabel"); // NOI18N

        endFNLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        endFNLabel.setText(resourceMap.getString("endFNLabel.text")); // NOI18N
        endFNLabel.setName("endFNLabel"); // NOI18N

        amountLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        amountLabel.setText(resourceMap.getString("amountLabel.text")); // NOI18N
        amountLabel.setName("amountLabel"); // NOI18N

        totalFNLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        totalFNLabel.setText(resourceMap.getString("totalFNLabel.text")); // NOI18N
        totalFNLabel.setName("totalFNLabel"); // NOI18N

        totalLabel.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        totalLabel.setText(resourceMap.getString("totalLabel.text")); // NOI18N
        totalLabel.setName("totalLabel"); // NOI18N

        amountTextField.setBackground(resourceMap.getColor("amountTextField.background")); // NOI18N
        amountTextField.setEditable(false);
        amountTextField.setText(resourceMap.getString("amountTextField.text")); // NOI18N
        amountTextField.setName("amountTextField"); // NOI18N

        totalFNTextField.setBackground(resourceMap.getColor("totalFNTextField.background")); // NOI18N
        totalFNTextField.setEditable(false);
        totalFNTextField.setText(resourceMap.getString("totalFNTextField.text")); // NOI18N
        totalFNTextField.setName("totalFNTextField"); // NOI18N

        totalPayTextField.setBackground(resourceMap.getColor("totalPayTextField.background")); // NOI18N
        totalPayTextField.setEditable(false);
        totalPayTextField.setText(resourceMap.getString("totalPayTextField.text")); // NOI18N
        totalPayTextField.setName("totalPayTextField"); // NOI18N

        totalPaymentLabel.setFont(resourceMap.getFont("totalPaymentLabel.font")); // NOI18N
        totalPaymentLabel.setText(resourceMap.getString("totalPaymentLabel.text")); // NOI18N
        totalPaymentLabel.setName("totalPaymentLabel"); // NOI18N

        totalFNsTextField.setBackground(resourceMap.getColor("totalFNsTextField.background")); // NOI18N
        totalFNsTextField.setEditable(false);
        totalFNsTextField.setText(resourceMap.getString("totalFNsTextField.text")); // NOI18N
        totalFNsTextField.setName("totalFNsTextField"); // NOI18N

        totalPaymentTextField.setBackground(resourceMap.getColor("totalPaymentTextField.background")); // NOI18N
        totalPaymentTextField.setEditable(false);
        totalPaymentTextField.setText(resourceMap.getString("totalPaymentTextField.text")); // NOI18N
        totalPaymentTextField.setName("totalPaymentTextField"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        regularizationTable.setForeground(resourceMap.getColor("regularizationTable.foreground")); // NOI18N
        regularizationTable.setModel(new DefaultTableModel(new Object[][] {{null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null}}, new String[] {"Número de Préstamo", "Plazo", "Año Inicio", "Qna. Inicio", "Año Fin", "Qna. Fin", "Monto Prestado", "Descuento"}){
            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        });
        regularizationTable.setName("regularizationTable"); // NOI18N
        jScrollPane1.setViewportView(regularizationTable);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        paymentTable.setModel(new DefaultTableModel(new Object[][] {{null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null, null}, {null, null, null, null, null}}, new String[] {"De:", "A:", "Importe", "Quincenas", "Total"}){
            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        });
        paymentTable.setName("paymentTable"); // NOI18N
        jScrollPane2.setViewportView(paymentTable);

        jLabel4.setFont(resourceMap.getFont("nombreLabel.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        addButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        addButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        addButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        addButton.setText(resourceMap.getString("addButton.text")); // NOI18N
        addButton.setActionCommand(resourceMap.getString("addButton.actionCommand")); // NOI18N
        addButton.setName("addButton"); // NOI18N

        removeButton.setBackground(resourceMap.getColor("reporteButton.background")); // NOI18N
        removeButton.setFont(resourceMap.getFont("reporteButton.font")); // NOI18N
        removeButton.setForeground(resourceMap.getColor("reporteButton.foreground")); // NOI18N
        removeButton.setText(resourceMap.getString("removeButton.text")); // NOI18N
        removeButton.setName("removeButton"); // NOI18N

        startYearSpinner.setName("startYearSpinner"); // NOI18N

        startFNSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 24, 1));
        startFNSpinner.setName("startFNSpinner"); // NOI18N

        endYearSpinner.setName("endYearSpinner"); // NOI18N

        endFNSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 24, 1));
        endFNSpinner.setName("endFNSpinner"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(startYearSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                .addComponent(startFNSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(startFNLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(endFNLabel)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(endYearSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(endFNSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(amountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(amountLabel))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(totalFNTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(totalFNLabel)))
                        .addGap(34, 34, 34)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(totalLabel)
                            .addComponent(totalPayTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26)
                        .addComponent(addButton)
                        .addGap(18, 18, 18)
                        .addComponent(removeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lastNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lastNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(30, 30, 30)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(secondNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(secondNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(20, 20, 20)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(nameLabel)
                                    .addComponent(firstNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(delegacionLabel)
                                .addGap(4, 4, 4)
                                .addComponent(delegacionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(ramoLabel)
                                .addGap(9, 9, 9)
                                .addComponent(ramoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(pagaduriaLabel)
                                .addGap(8, 8, 8)
                                .addComponent(pagaduriaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(noIsssteLabel)
                                .addGap(2, 2, 2)
                                .addComponent(noIsssteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(rfcLabel)
                                .addGap(6, 6, 6)
                                .addComponent(rfcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(curpLabel)
                                .addGap(9, 9, 9)
                                .addComponent(curpTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(dealTypeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(10, 10, 10)
                            .addComponent(dealTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(brokenFNLabel)
                            .addGap(9, 9, 9)
                            .addComponent(brokenFNTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(totalPaymentLabel)
                            .addGap(22, 22, 22)
                            .addComponent(totalFNsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(totalPaymentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(delegacionLabel)
                    .addComponent(delegacionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ramoLabel)
                    .addComponent(ramoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pagaduriaLabel)
                    .addComponent(pagaduriaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(noIsssteLabel)
                    .addComponent(noIsssteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rfcLabel)
                    .addComponent(rfcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(curpLabel)
                    .addComponent(curpTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lastNameLabel)
                    .addComponent(nameLabel)
                    .addComponent(secondNameLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(firstNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lastNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4))
                    .addComponent(secondNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(brokenFNLabel)
                    .addComponent(brokenFNTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dealTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dealTypeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(startFNLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(startYearSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addButton)
                            .addComponent(removeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(endFNLabel)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(endYearSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(startFNSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addComponent(endFNSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(totalPayTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(amountLabel)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(totalFNLabel)
                                .addComponent(totalLabel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(amountTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(totalFNTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalPaymentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(totalPaymentLabel)
                    .addComponent(totalFNsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(900, 70));

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(70, 70));

        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel5.setIcon(resourceMap.getIcon("jLabel5.icon")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel5.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setPreferredSize(new java.awt.Dimension(792, 70));

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addContainerGap(179, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addGap(24, 24, 24))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 832, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 972, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
        );

        setComponent(mainPanel);
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Sets URL value XML file, to <code>url</code> class variable
     * @param xmlURL xml file URL
     */
    private void loadXML(URL xmlURL) {
        try {
            url = xmlURL;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Unique instance of class <code>JAXBContext</code>
     * @throws JAXBException
     */
    private void getInstanceJAXBContext() throws JAXBException {
        if (context == null) {
            context = JAXBContext.newInstance(RamoManual.class);
        }
    }

    /**
     * This method gets a unique instance of <code>Marshaller</code>
     * @return <code>Marshaller</code> object for marshalling process
     * @throws JAXBException
     */
    private Marshaller getMarshaller() throws JAXBException {
        if (marshaller == null) {
            marshaller = context.createMarshaller();
        }

        return marshaller;
    }

    /**
     * This method gets a unique instance of <code>Unmarshaller</code>
     * @return code>Unmarshaller</code> object for unmarshalling process
     * @throws JAXBException
     */
    private Unmarshaller getUnmarshaller() throws JAXBException {
        if (unmarshaller == null) {
            unmarshaller = context.createUnmarshaller();
        }

        return unmarshaller;
    }

    /**
     * Process of deserializing XML data into <code>RamoManual</code> Java class
     * @param url URL XML file
     * @throws JAXBException
     */
    private void readXML(URL url) throws JAXBException {
        rootNode = (RamoManual) getUnmarshaller().unmarshal(url);
    }

    /**
     * Process of serializing <code>RamoManual</code> Java class back into XML data
     * @param url URL XML file
     * @throws JAXBException
     */
    private void writeXML(URL url) throws JAXBException {
        StreamResult result = new StreamResult(url.getPath());
        getMarshaller().marshal(rootNode, result);
    }

    /**
     * Load element data into form application
     * @param element derechohabiente data
     */
    private void loadElementData(Derechohabiente element) {
        delegacionTextField.setText(element.getDelegacion());
        ramoTextField.setText(element.getRamo());
        pagaduriaTextField.setText(element.getPagaduria());
        noIsssteTextField.setText(element.getNoIssste());
        rfcTextField.setText(element.getRfc());
        curpTextField.setText(element.getCurp());
        lastNameTextField.setText(element.getPersona().getAPaterno());
        secondNameTextField.setText(element.getPersona().getAMaterno());
        firstNameTextField.setText(element.getPersona().getNombre());
        brokenFNTextField.setText(element.getQuincenaCorte());
        totalFNsTextField.setText(element.getQuincenaTotal());
        totalPaymentTextField.setText(element.getImporteTotal());
        setRegularizationRange(element.getRegularizacion().getListaOrdenDescuento());
        setCellValues(regularizationTable, element.getRegularizacion().getListaOrdenDescuento());
        setCellValues(paymentTable, element.getAmortizacion().getListaPago());
        totalEstimate(element);
        amountTextField.setText("");
        totalFNTextField.setText("");
        totalPayTextField.setText("");

        if (element.getTipoMovimiento() == null) {
            element.setTipoMovimiento("");
            dealTypeComboBox.setSelectedIndex(0);
        } else {
            if (!element.getTipoMovimiento().equals("")) {
                dealTypeComboBox.setSelectedItem(element.getTipoMovimiento());
            } else {
                dealTypeComboBox.setSelectedIndex(0);
            }
        }
    }

    /**
     * Sets element data values into cells table
     * @param table table for data load
     * @param data element data as <code>ArrayList</code>
     */
    private void setCellValues(JTable table, ArrayList data) {
        DefaultTableModel defaultModel = (DefaultTableModel) table.getModel();
        Object arrayData[] = {};

        defaultModel.getDataVector().removeAllElements();

        if (data != null) {
            for (int i = 0; i < data.size(); i++) {
                if (!data.isEmpty()) {
                    if (data.get(i) instanceof OrdenDescuento) {
                        arrayData = ((ArrayList<OrdenDescuento>) data).get(i).getElements();
                    } else if (data.get(i) instanceof Pago) {
                        arrayData = ((ArrayList<Pago>) data).get(i).getElementsRange();
                    }
                }

                if (i > table.getRowCount() - 1) {
                    defaultModel.addRow(arrayData);
                }

                for (int j = 0; j < table.getColumnCount(); j++) {
                    table.setValueAt(arrayData[j], i, j);
                    defaultModel.fireTableCellUpdated(i, j);
                    defaultModel.fireTableStructureChanged();
                }
            }
        }

        defaultModel.fireTableDataChanged();
        table.repaint();
    }

    /**
     * Gets the next element in the elements ordenList
     * @return returns found element <code>Derechohabiente</code>
     */
    private Object nextElement() {
        Object array[] = rootNode.getListaDerechohabiente().toArray();
        dataPersistence();
        if (cursor < array.length - 1) {
            currentElement = (Derechohabiente) array[++cursor];
            return currentElement;
        }
        return null;
    }

    /**
     * Gets the previous element in the elements ordenList
     * @return returns found element <code>Derechohabiente</code>
     */
    private Object previousElement() {
        Object array[] = rootNode.getListaDerechohabiente().toArray();
        dataPersistence();
        if (cursor > 0) {
            currentElement = (Derechohabiente) array[--cursor];
            return currentElement;
        }
        return null;
    }

    /**
     * Sets regularization range, calculates the minimum and maximum value for regularization fortnight an year
     * @param ordenDescuentoList regularization ordenList
     */
    private void setRegularizationRange(ArrayList<OrdenDescuento> ordenDescuentoList) {
        if (ordenDescuentoList.isEmpty()) {
            return;
        }

        Calendar todaysDate = Calendar.getInstance();
        int startYear = 0, endYear = 0, startFn = 0, endFn = 0;
        OrdenDescuento ordenVar;

        orderList(ordenDescuentoList, false);
        ordenVar = (OrdenDescuento) ordenDescuentoList.get(ordenDescuentoList.size() - 1);
//        endYear = Integer.parseInt(ordenVar.getAnioFin());
//        endFn = Integer.parseInt(ordenVar.getQnaFin());
        endFn = Quincena.getQuincenaVencida(todaysDate.getTime());
        endYear = todaysDate.get(Calendar.YEAR);
        endYear = endFn == 24 ? endYear - 1 : endYear;
        currentEndRange = new Quincena(endYear, endFn);
        brokenFNTextField.setText(currentEndRange.toString());

        orderList(ordenDescuentoList, true);
        ordenVar = (OrdenDescuento) ordenDescuentoList.get(0);
        startYear = Integer.parseInt(ordenVar.getAnioIni());
        startFn = Integer.parseInt(ordenVar.getQnaIni());
        currentStartRange = new Quincena(startYear, startFn);

        startYearSpinner.setModel(new javax.swing.SpinnerNumberModel(startYear, startYear, endYear, 1));
        startYearSpinner.setEditor(new JSpinner.NumberEditor(startYearSpinner, "#"));
        endYearSpinner.setModel(new javax.swing.SpinnerNumberModel(endYear, startYear, endYear, 1));
        endYearSpinner.setEditor(new JSpinner.NumberEditor(endYearSpinner, "#"));
    }

    /**
     * Sort a ordenList of items <code>Pago</code>, <code>OrdenDescuento</code>
     * @param ordenList sort ordenList
     * @param initial initial ascending sort
     */
    private void orderList(List list, final boolean initial) {
        Collections.sort(list, new Comparator() {

            public int compare(Object obj1, Object obj2) {
                if (obj1 instanceof OrdenDescuento || obj1 instanceof Pago) {
                    Class clase = obj1.getClass();
                    try {
                        String yearMethod = initial ? "getAnioIni" : "getAnioFin";
                        String fnMethod = initial ? "getQnaIni" : "getQnaFin";

                        Method getYear = clase.getMethod(yearMethod);
                        Method getFn = clase.getMethod(fnMethod);

                        Object year1 = getYear.invoke(obj1);
                        Object fn1 = getFn.invoke(obj1);
                        Object year2 = getYear.invoke(obj2);
                        Object fn2 = getFn.invoke(obj2);

                        if (year1 instanceof Comparable && fn1 instanceof Comparable
                                && year2 instanceof Comparable && fn2 instanceof Comparable) {

                            Comparable y1 = (Comparable) year1;
                            Comparable fnc1 = (Comparable) fn1;
                            Comparable y2 = (Comparable) year2;
                            Comparable fnc2 = (Comparable) fn2;

                            if (y1.compareTo(y2) == 0) {
                                return fnc1.compareTo(fnc2);
                            } else {
                                return y1.compareTo(y2);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return 0;
                } else {
                    throw new UnsupportedOperationException("Error: list not supported");
                }
            }
        });
    }

    /**
     * calculates total payment and fortnight
     * @param element current element
     */
    private void totalEstimate(Derechohabiente element) {
        Integer fns = new Integer(0);
        Double totals = new Double(0);
        try {
            if (element.getAmortizacion().getListaPago() != null) {
                for (Pago pago : element.getAmortizacion().getListaPago()) {
                    fns = fns + Integer.parseInt(pago.getQuincenas());
                    totals = totals + Double.parseDouble(pago.getPagoTotal());
                }
            }
        } catch (Exception e) {
            fns = 0;
            totals = 0.0;
            e.printStackTrace();
        } finally {
            element.setQuincenaTotal(fns.toString());
            element.setImporteTotal(totals.toString());
            totalFNsTextField.setText(element.getQuincenaTotal());
            totalPaymentTextField.setText(element.getImporteTotal());
        }
    }

    /**
     * corregir validacion ordenList traslapadas
     * Adds a payment to the ordenList
     */
    private void addPayment() {
        Quincena startFN = new Quincena((Integer) startYearSpinner.getValue(), (Integer) startFNSpinner.getValue());
        Quincena endFN = new Quincena((Integer) endYearSpinner.getValue(), (Integer) endFNSpinner.getValue());
        Pago payment = null;
        String message = "";
        int status = 1;

        if (Quincena.compareQuincenas(startFN, endFN) < 1) {
            if (startFN.isInRange(currentStartRange, currentEndRange) && endFN.isInRange(currentStartRange, currentEndRange)) {
                ArrayList<OrdenDescuento> ordenes = currentElement.getRegularizacion().getListaOrdenDescuento();
                for (OrdenDescuento orden : ordenes) {
                    if (startFN.isInRange(orden.getRangoIni(), orden.getRangoFin())
                            && endFN.isInRange(orden.getRangoIni(), orden.getRangoFin())) {

                        Integer fns = new Integer(Quincena.quincenasEntre(startFN, endFN, false));
                        fns = fns + 1;
                        BigDecimal totalPayment = new BigDecimal(orden.getDescuento()).multiply(new BigDecimal(fns.intValue()));

                        payment = new Pago();
                        payment.setAnioIni(new Integer(startFN.getAnio()).toString());
                        payment.setQnaIni(new Integer(startFN.getQuincena()).toString());
                        payment.setAnioFin(new Integer(endFN.getAnio()).toString());
                        payment.setQnaFin(new Integer(endFN.getQuincena()).toString());
                        payment.setQuincenas(fns.toString());
                        payment.setImporte(orden.getDescuento());
                        payment.setPagoTotal(totalPayment.toPlainString());

                        status = 0;

                        if (currentElement.getAmortizacion().getListaPago() == null) {
                            currentElement.getAmortizacion().setListaPago(new ArrayList<Pago>());
                        }

                        for (Pago p : currentElement.getAmortizacion().getListaPago()) {
                            if (payment.equals(p) || startFN.isInRange(p.getRangoIni(), p.getRangoFin())
                                    || endFN.isInRange(p.getRangoIni(), p.getRangoFin())) {
                                status = 2;
                                break;
                            }
                        }
                    }
                }
            }
        }

        if (status == 0) {
            currentElement.getAmortizacion().getListaPago().add(payment);
            orderList(currentElement.getAmortizacion().getListaPago(), true);

            amountTextField.setText(payment.getImporte());
            totalFNTextField.setText(payment.getQuincenas());
            totalPayTextField.setText(payment.getPagoTotal());

            message = "Se ha añadido el pago al archivo exitosamente";
            setCellValues(paymentTable, currentElement.getAmortizacion().getListaPago());
            totalEstimate(currentElement);
        } else {
            amountTextField.setText("");
            totalFNTextField.setText("");
            totalPayTextField.setText("");
            if (status == 1) {
                message = "El rango de pago no coincide con en el de orden de descuento";
            } else if (status == 2) {
                message = "El pago se encuentra en el rango de pagos añadidos";
            } else if (status == 3) {
                message = "El pago se encuentra entre distintos rangos de orden de descuento";
            } else {
                message = "Ocurrió un error al añadir el pago";
            }
        }

        int icon = status == 0 ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.OK_OPTION;

        JOptionPane.showMessageDialog(null, message, "Añadir Pago", icon);

    }

    /**
     * Removes a payment selected range from the ordenList
     */
    private void removePayment() {
        String message = "";
        boolean status = false;
        int i = paymentTable.getSelectedRow();
        if (i != -1) {
            List<Pago> pagos = currentElement.getAmortizacion().getListaPago();
            for (Pago pago : pagos) {
                if (pago.equals(pagos.toArray()[i])) {
                    pagos.remove(i);
                    status = true;
                    break;
                }
            }
        }
        if (status) {
            message = "Se ha eliminado el pago exitosamente";
            setCellValues(paymentTable, currentElement.getAmortizacion().getListaPago());
            totalEstimate(currentElement);
        } else {
            message = "Ocurrió un error al eliminar el pago";
        }

        int icon = status ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.OK_OPTION;
        JOptionPane.showMessageDialog(null, message, "Eliminar Pago", icon);
    }

    /**
     * Sets enabled property for functional components
     * @param enabled sets enabled true or false
     */
    private void componentEnabled(boolean enabled) {
        dealTypeComboBox.setEnabled(enabled);
        startYearSpinner.setEnabled(enabled);
        startFNSpinner.setEnabled(enabled);
        endYearSpinner.setEnabled(enabled);
        endFNSpinner.setEnabled(enabled);
        addButton.setEnabled(enabled);
        removeButton.setEnabled(enabled);
        reporteContenidoButton.setEnabled(enabled);
        reporteConciliacionButton.setEnabled(enabled);
        loadXMLButton.setEnabled(!enabled);
        saveFileButton.setEnabled(enabled);
        searchButton.setEnabled(enabled);
        previousElementButton.setEnabled(enabled);
        nextElementButton.setEnabled(enabled);
    }

    /**
     * Function handler, receives buttons dispatched events
     * @param event
     */
    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == loadXMLButton) {
            int returnVal = siicDataFileChooser.showOpenDialog(mainPanel);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    readXML(siicDataFileChooser.getSelectedFile().toURI().toURL());
                    loadXML(siicDataFileChooser.getSelectedFile().toURI().toURL());
                    writeXML(url);
                    process();
                    componentEnabled(true);
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "File: " + ex.getStackTrace()[0].getFileName()
                            + "\nClass: " + ex.getStackTrace()[0].getClassName()
                            + "\nMethod: " + ex.getStackTrace()[0].getMethodName()
                            + "\nLine: " + ex.getStackTrace()[0].getLineNumber(), ex.toString(), JOptionPane.ERROR_MESSAGE);
                    ex.printStackTrace();
                }
            }
        } else if (event.getSource() == saveFileButton) {
            try {
                writeXML(url);
            } catch (JAXBException ex) {
                Logger.getLogger(RamosManualesView.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (event.getSource() == nextElementButton) {
            Derechohabiente siguiente = (Derechohabiente) nextElement();
            if (siguiente != null) {
                loadElementData(siguiente);
            }
        } else if (event.getSource() == previousElementButton) {
            Derechohabiente anterior = (Derechohabiente) previousElement();
            if (anterior != null) {
                loadElementData(anterior);
            }
        } else if (event.getSource() == addButton) {
            addPayment();
        } else if (event.getSource() == removeButton) {
            removePayment();
        } else if (event.getSource() == reporteContenidoButton) {
            generateReport(REPORTE_CONTENIDO);
        } else if (event.getSource() == reporteConciliacionButton) {
            generateReport(REPORTE_CONCILIACION);
        }
    }

    /**
     * Action listener for search dialog
     */
    @Action
    public void showSearchDialog() {
        JFrame mainFrame = RamosManualesApp.getApplication().getMainFrame();
        if (searchDialog == null) {
            searchDialog = new ItemsSearchDialog(mainFrame, rootNode.getListaDerechohabiente());
        }

        searchDialog.setLocationRelativeTo(mainFrame);
        RamosManualesApp.getApplication().show(searchDialog);
    }

    /**
     * Function handler, receives dispatched event for exitButton
     * @param evt event dispatched
     */
    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
        int response = JOptionPane.showConfirmDialog(mainPanel, "¿Desea guardar los cambios?", "Salir", JOptionPane.YES_NO_CANCEL_OPTION);
        if (response == JOptionPane.YES_OPTION) {
            dataPersistence();
            try {
                writeXML(url);
            } catch (JAXBException ex) {
                Logger.getLogger(RamosManualesView.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.exit(0);
        } else if (response == JOptionPane.NO_OPTION) {
            System.exit(0);
        } else {
            return;
        }
    }//GEN-LAST:event_exitButtonActionPerformed

    /**
     * Function handler, receives deal type combo box dispatched event
     * @param evt
     */
    private void dealTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dealTypeComboBoxActionPerformed
        if (evt.getActionCommand().equals("comboBoxChanged")) {
            JComboBox combo = (JComboBox) evt.getSource();
            if (combo.getSelectedIndex() != 0) {
                addButton.setEnabled(false);
            } else {
                addButton.setEnabled(true);
            }
        }
    }//GEN-LAST:event_dealTypeComboBoxActionPerformed

    /**
     * initialize process
     */
    private void process() {
        try {
            cursor = 0;
            if (rootNode.getListaDerechohabiente().isEmpty()) {
                throw new NullPointerException("La lista de derechohabientes se encuentra vacía");
            }
            Derechohabiente firstElement = (Derechohabiente) rootNode.getListaDerechohabiente().toArray()[0];
            currentElement = firstElement;
            loadElementData(currentElement);
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "File: " + e.getStackTrace()[0].getFileName()
                    + "\nClass: " + e.getStackTrace()[0].getClassName()
                    + "\nMethod: " + e.getStackTrace()[0].getMethodName()
                    + "\nLine: " + e.getStackTrace()[0].getLineNumber(),
                    e.toString(), JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * This method generates 'contenido' and 'conciliacion' reports loaded from form's application source
     * @param report 0:contenido, 1:conciliacion
     */
    private void generateReport(int report) {
        try {
            JasperReport jasperReport = null;
            JRBeanCollectionDataSource dataSource = null;

            String reportPath = "/ramosmanuales/resources/reportes/";
            String reportName = getReportName(report);

            InputStream reportStream = this.getClass().getResourceAsStream(reportPath + reportName);

            try {
                //String reportPath = "./resources/reportes/";
                //URL reportURL = this.getClass().getResource(reportPath + reportName);
                //jasperReport = (JasperReport) JRLoader.loadObject(reportURL);
                jasperReport = (JasperReport) JRLoader.loadObject(reportStream);
            } catch (JRException e) {
                e.printStackTrace();
            }

            Collection reportDataSource = setReportData(report);
            dataSource = new JRBeanCollectionDataSource(reportDataSource);

            Map parameters = new HashMap();
            String TITLE = report == 0 ? "Reporte de Contenido" : "Reporte de Conciliación";
            parameters.put("TITLE", TITLE);

            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);

            JasperViewer jViewer = new JasperViewer(jasperPrint, false);
            jViewer.setTitle(TITLE);
            jViewer.setVisible(true);
            System.out.println("imprimiendo reporte n__n");
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "File: " + ex.getStackTrace()[0].getFileName()
                    + "\nClass: " + ex.getStackTrace()[0].getClassName()
                    + "\nMethod: " + ex.getStackTrace()[0].getMethodName()
                    + "\nLine: " + ex.getStackTrace()[0].getLineNumber(),
                    ex.toString(), JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * Returns specified report name
     * @param report 0:contenido, 1:conciliacion
     * @return report name
     * @throws UnsupportedOperationException
     */
    private String getReportName(int report) throws UnsupportedOperationException {
        String reportName = null;

        switch (report) {
            case REPORTE_CONTENIDO:
                reportName = "ReporteContenido.jasper";
                break;

            case REPORTE_CONCILIACION:
                reportName = "ReporteConciliacion.jasper";
                break;

            default:
                throw new UnsupportedOperationException("Report not found");
        }

        return reportName;
    }

    /**
     * @param report 0:contenido, 1:conciliacion
     * @return collection data source
     * @throws NullPointerException
     */
    private Collection setReportData(int report) throws NullPointerException {
        Collection reportData = null;
        switch (report) {
            case REPORTE_CONTENIDO:
                if (rootNode != null) {
                    if (!rootNode.getListaDerechohabiente().isEmpty()) {
                        reportData = new ArrayList();
                        for (Derechohabiente derechohabiente : rootNode.getListaDerechohabiente()) {
                            for (OrdenDescuento orden : derechohabiente.getRegularizacion().getListaOrdenDescuento()) {
                                ReporteContenido contenido = new ReporteContenido();

                                contenido.setDelegacion(derechohabiente.getDelegacion());
                                contenido.setRamo(derechohabiente.getRamo());
                                contenido.setPagaduria(derechohabiente.getPagaduria());
                                contenido.setRfc(derechohabiente.getRfc());
                                contenido.setNoIssste(derechohabiente.getNoIssste());
                                contenido.setCurp(derechohabiente.getCurp());
                                contenido.setNombre(derechohabiente.getPersona().getNombreCompleto());
                                contenido.setNoPrestamo(orden.getNoPrestamo());
                                contenido.setImporte(orden.getMonto());
                                contenido.setPlazo(orden.getPlazo());
                                contenido.setDescuento(orden.getDescuento());
                                contenido.setQnaInicial(orden.getQnaIni());

                                reportData.add(contenido);
                            }
                        }
                    } else {
                        throw new NullPointerException("No se tienen los datos necesarios datos para generar el reporte");
                    }
                } else {
                    throw new NullPointerException("La lista de derechohabientes está vacía");
                }
                break;
            case REPORTE_CONCILIACION:
                if (rootNode != null) {
                    if (!rootNode.getListaDerechohabiente().isEmpty()) {
                        reportData = new ArrayList();
                        for (Derechohabiente derechohabiente : rootNode.getListaDerechohabiente()) {
                            ReporteConciliacion conciliacion = null;
                            if (derechohabiente.getTipoMovimiento().equals("NORMAL")) {
                                for (OrdenDescuento orden : derechohabiente.getRegularizacion().getListaOrdenDescuento()) {
                                    for (Pago pago : derechohabiente.getAmortizacion().getListaPago()) {
                                        if (Double.parseDouble(pago.getImporte()) == Double.parseDouble(orden.getDescuento())) {
                                            conciliacion = new ReporteConciliacion();

                                            conciliacion.setDelegacion(derechohabiente.getDelegacion());
                                            conciliacion.setRamo(derechohabiente.getRamo());
                                            conciliacion.setPagaduria(derechohabiente.getPagaduria());
                                            conciliacion.setRfc(derechohabiente.getRfc());
                                            conciliacion.setNoIssste(derechohabiente.getNoIssste());
                                            conciliacion.setCurp(derechohabiente.getCurp());
                                            conciliacion.setNombre(derechohabiente.getPersona().getNombreCompleto());
                                            conciliacion.setNoPrestamo(orden.getNoPrestamo());
                                            conciliacion.setPlazo(orden.getPlazo());
                                            conciliacion.setQnaInicial(pago.getRangoIni().toString());
                                            conciliacion.setQnaFinal(pago.getRangoFin().toString());
                                            conciliacion.setMonto(pago.getPagoTotal());
                                            conciliacion.setDescuento(pago.getImporte());
                                            conciliacion.setMovimiento(derechohabiente.getTipoMovimiento());

                                            reportData.add(conciliacion);
                                        }
                                    }
                                }
                            } else {
                                conciliacion = new ReporteConciliacion();

                                conciliacion.setDelegacion(derechohabiente.getDelegacion());
                                conciliacion.setRamo(derechohabiente.getRamo());
                                conciliacion.setPagaduria(derechohabiente.getPagaduria());
                                conciliacion.setRfc(derechohabiente.getRfc());
                                conciliacion.setNoIssste(derechohabiente.getNoIssste());
                                conciliacion.setCurp(derechohabiente.getCurp());
                                conciliacion.setNombre(derechohabiente.getPersona().getNombreCompleto());
                                conciliacion.setNoPrestamo("0");
                                conciliacion.setPlazo("0");
                                conciliacion.setQnaInicial("0");
                                conciliacion.setQnaFinal("0");
                                conciliacion.setMonto("0");
                                conciliacion.setDescuento("0");
                                conciliacion.setMovimiento(derechohabiente.getTipoMovimiento());

                                reportData.add(conciliacion);
                            }
                        }
                    } else {
                        throw new NullPointerException("no se tienen los datos necesarios datos para generar el reporte");
                    }
                } else {
                    throw new NullPointerException("La lista de derechohabientes está vacía");
                }
                break;

            default:
                System.out.println("report not supported");
                break;
        }

        return reportData;
    }

    /**
     * Performs form data persistence on elements iteration
     */
    private void dataPersistence() {
        if (currentElement != null) {
            if (!currentElement.getTipoMovimiento().equals(dealTypeComboBox.getSelectedItem())) {
                currentElement.setTipoMovimiento(dealTypeComboBox.getSelectedItem().toString());
                currentElement.setQuincenaTotal(totalFNsTextField.getText());
                currentElement.setImporteTotal(totalPaymentTextField.getText());
                currentElement.setQuincenaCorte(brokenFNTextField.getText());
            }
        }
    }
}
